package cn.wolfcode.cloud.shop.mapper;


import cn.wolfcode.cloud.shop.domain.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Set;

/**
 * @author Administrator
 */
@Mapper
public interface GoodsMapper {

    @SelectProvider(type = GoodsSelectProvider.class,method = "selectByIdSet")
    List<Goods> selectByIdSet(@Param("idSet") Set<Long> idSet);

    class GoodsSelectProvider {

        //返回sql语句
        public String selectByIdSet(Set<Long> idSet){
            if(CollectionUtils.isEmpty(idSet)){
                return null;
            }

            StringBuilder sb = new StringBuilder(100);
            sb.append("select * from t_goods where id in (");
            for (Long id : idSet) {
                sb.append(id.toString()).append(",");
            }
            sb.deleteCharAt(sb.length()-1);
            sb.append(")");
            return sb.toString();
        }
    }
}
